f = open('tet.txt', 'r', encoding='utf-8')
header = f.readline().strip().split(',')
text_data = [i.strip().split(',') for i in f]


tmp_list = [
    #  临时列表，用于计算查询多少条数据
]

while True:
    tmp_list.clear()
    user_input = input('股票查询接口(输入exit退出程序)>>>:').strip()
    if user_input == '':
        print('输入值为空，请重新输入....')
        continue

    if '<' in user_input:  # 出现'<' 逻辑处理过程
        n1_index = user_input.index('<')
        n1_heat = user_input[:n1_index]
        n1_data = user_input[n1_index + 1:]
        sou_index = header.index(n1_heat)
        if n1_heat in header:
            for row in text_data:
                if '%' in row[sou_index]:
                    if float(row[sou_index][0:-1]) < float(n1_data):
                        tmp_list.append(row)
                elif '亿' in row[sou_index]:
                    if float(row[sou_index][0:-1]) * 10000 < float(n1_data):
                        tmp_list.append(row)
                elif '万' in row[sou_index]:
                    if float(row[sou_index][0:-1]) < float(n1_data):
                        tmp_list.append(row)
                else:
                    if float(row[sou_index]) < float(n1_data):
                        tmp_list.append(row)
            print(', '.join(header))
            for i in tmp_list:
                print(',   '.join(i))
            print(f'共计找到{len(tmp_list)}条....')
    elif '>' in user_input:  # 出现'>' 逻辑处理过程
        n2_index = user_input.index('>')
        n2_heat = user_input[:n2_index]
        n2_data = user_input[n2_index + 1:]
        sou_index = header.index(n2_heat)
        if n2_heat in header:
            for row in text_data:
                if '%' in row[sou_index]:
                    if float(row[sou_index][0:-1]) > float(n2_data):
                        tmp_list.append(row)
                elif '亿' in row[sou_index]:
                    if float(row[sou_index][0:-1]) * 10000 > float(n2_data):
                        tmp_list.append(row)
                elif '万' in row[sou_index]:
                    if float(row[sou_index][0:-1]) > float(n2_data):
                        tmp_list.append(row)
                else:
                    if float(row[sou_index]) > float(n2_data):
                        tmp_list.append(row)
            print(',   '.join(header))
            for i in tmp_list:
                print(',   '.join(i))
            print(f'共计找到{len(tmp_list)}条....')
    elif user_input == 'exit':
        exit("我退出啦..........")
    else:
        print(',   '.join(header))
        for vague in text_data:
            if user_input in vague[1]:
                tmp_list.append(vague)
        for i in tmp_list:
            print(',    '.join(i))
        print(f'共计找到{len(tmp_list)}条....')
